/*
	File:		Projectile.cpp
	Author:		Ben Feldmann
	Purpose:	Class to manage game projectiles
*/

#include "Projectile.h"
#include "Animation.h"
#include "EventSystem.h"
//#include "ObjectManager.h"


Animation* fire = new Animation;
Projectile::Projectile()
{
	fire->LoadAnimationFromFile("FireAnimation.xml");
	fire->Play(true);

	type = OBJ_BULLET;

	//ObjectManager::GetInstance()->AddObject(this);
}

void Projectile::Update(float elapsed) 
{
	SetX(GetX() + GetMoveSpeed()*elapsed);
	fire->Update(elapsed);
}

void Projectile::Render() 
{
	fire->Render(int(GetX()), int(GetY()), 1.0f, D3DCOLOR_XRGB(255, 255, 255), false);

	//if(GetTextureID() != -1)
	//{
	//	CSGD_TextureManager::GetInstance()->Draw(GetTextureID(), int(GetX()), int(GetY()));
	//}
}

bool Projectile::CheckCollision(IEntity* base) 
{
	if(Entity::CheckCollision(base) == true && base != this->GetOwner())
	{
		// Send the "target_hit" event
		EventSystem::GetInstance()->SendEvent("target_hit", base, /*(void*)&*//*(float*)&*/&this->damage);
		return true;
	}
	else
		return false;
}
